import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/home.vue";
import Index from "../views/index.vue";

Vue.use(VueRouter);

export const routes = [{
        path: "/",
        name: "Home",
        component: Home,
        meta: {
            title: "档案管理系统",
            authCode: 1000000
        },

        children: [{
                path: "/index",
                name: "Index",
                component: Index,
                meta: {
                    title: "分支机构/ 查看分支机构档案详情",
                    desc: "档案中心-窍楚档案"
                },
            },
            {
                path: "/boxDetail/:id",
                name: "BoxDetail",
                component: () =>
                    import ("../views/box-detail.vue"),
                meta: {
                    title: "窍详情"
                },
            },
            {
                path: "/orderDetail/:id",
                name: "OrderDetail",
                component: () =>
                    import ("../views/order-detail.vue"),
                meta: {
                    title: "订单详情"
                }
            },
            {
                path: "/user/report",
                name: "Report",
                component: () =>
                    import ("../views/inventory-report/index.vue"),
                meta: {
                    title: "盘点报表",
                    authCode: 1010400
                },
            },
            {
                path: "/agreement",
                name: "Agreement",
                component: () =>
                    import ("../views/agreement.vue"),
                meta: {
                    title: "协议",
                },
            },
            {
                path: "/user",
                name: "User",
                redirect: "/user/profile",
                component: () =>
                    import ("../views/member/index.vue"),
                meta: {
                    title: "用户中心",
                    authCode: 1010000
                },
                children: [{
                        path: "profile",
                        component: () =>
                            import ("../views/member/profile.vue"),
                        meta: {
                            title: "修改资料",
                            authCode: 1010100
                        },

                    },
                    {
                        path: "empower",
                        component: () =>
                            import ("../views/member/empower.vue"),
                        meta: {
                            title: "授权账号",
                            // authCode: 1010200
                        },
                    },
                    {
                        path: "bill",
                        component: () =>
                            import ("../views/member/bill.vue"),
                        meta: {
                            title: "我的账单",
                            // authCode: 1010300
                        },
                    },
                    {
                        path: "address",
                        component: () =>
                            import ("../views/member/address.vue"),
                        meta: {
                            title: "地址管理",
                            authCode: 1010500
                        },
                    },
                    {
                        path: "entry",
                        component: () =>
                            import ("../views/member/entry.vue"),
                        meta: {
                            title: "进库管理",
                            // authCode: 1010700
                        },
                    },
                    {
                        path: "rfid",
                        component: () =>
                            import ("../views/member/rfid.vue"),
                        meta: {
                            title: "标签更换",
                            // authCode: 1010800
                        },
                    },
                    {
                        path: "password",
                        component: () =>
                            import ("../views/member/password.vue"),
                        meta: {
                            title: "修改密码",
                            authCode: 1010600
                        },
                    },
                    // {
                    //     path: "warehousing",
                    //     component: () =>
                    //         import ("../views/member/warehousing.vue"),
                    //     meta: {
                    //         title: "待入库列表",
                    //         authCode: 1010900
                    //     },
                    // },
                ],
            },
            {
                path: "/dashboard",
                name: "dashboard",
                redirect: "/retrieval/apply",
                component: () =>
                    import ("../views/access-manage/index.vue"),
                meta: {
                    title: "档案中心",
                    authCode: 1020000
                },
                children: [{
                    path: "access",
                    name: "WarehousingRecord",
                    component: () =>
                        import ("../views/access-manage/warehousing-record.vue"),
                    meta: {
                        title: "出入库记录"
                    },
                }]
            },
            {
                path: "/retrieval",
                name: "accessManage",
                redirect: "/retrieval/log",
                component: () =>
                    import ("../views/access-manage/index.vue"),
                meta: {
                    title: "调阅管理",
                    authCode: 1020000
                },
                children: [{
                        path: "apply",
                        name: 'applyRead',
                        component: () =>
                            import ("../views/access-manage/apply-read.vue"),
                        meta: {
                            title: "申请调阅",
                            authCode: 1020100
                        },
                    },
                    {
                        path: "to-apply", // 申请按钮的功能
                        component: () =>
                            import ("../views/access-manage/apply-read.vue"),
                        meta: {
                            title: "申请",
                            authCode: 1021100,
                            type: 3,
                            showNav: false
                        },
                    },
                    {
                        path: "approve",
                        component: () =>
                            import ("../views/access-manage/read-approval.vue"),
                        meta: {
                            title: "调阅审批",
                            authCode: 1020200
                        },
                    },
                    {
                        path: "log",
                        component: () =>
                            import ("../views/access-manage/read-log.vue"),
                        meta: {
                            title: "调阅列表",
                            authCode: 1020300
                        },
                    },
                    {
                        path: "temp",
                        name: "AccessTempList",
                        component: () =>
                            import ("../views/access-manage/access-temp-list.vue"),
                        meta: {
                            title: "临时调阅列表"
                        },
                    },
                    // {
                    //     path: "warehousing-record",
                    //     name: "WarehousingRecord",
                    //     component: () =>
                    //         import ("../views/access-manage/warehousing-record.vue"),
                    //     meta: {
                    //         title: "出入库记录"
                    //     },
                    // },
                ],
            },
            {
                path: "/back",
                name: "backWarehouse",
                redirect: "/back/log",
                component: () =>
                    import ("../views/back-warehouse-manage/index.vue"),
                meta: {
                    title: "回库管理",
                    authCode: 1030000
                },
                children: [{
                        path: "apply",
                        component: () =>
                            import ("../views/back-warehouse-manage/apply-back.vue"),
                        meta: {
                            title: "申请回库",
                            authCode: 1030100
                        },
                    },
                    {
                        path: "log",
                        name: 'backLogList',
                        component: () =>
                            import ("../views/back-warehouse-manage/back-log.vue"),
                        meta: {
                            title: "回库记录",
                            authCode: 1030200
                        },
                    },
                    {
                        path: "temp",
                        name: "BackTempList",
                        component: () =>
                            import ("../views/access-manage/access-temp-list.vue"),
                        meta: {
                            title: "临时回库列表"
                        },
                    },
                    {
                        path: "apply-button", // 申请功能
                        meta: {
                            title: "申请",
                            authCode: 1031100,
                            showNav: false
                        },
                    },
                ],
            },
            {
                path: "/destroy",
                name: "Destroy",
                redirect: "/destroy/log",
                component: () =>
                    import ("../views/destroy-manage/index.vue"),
                meta: {
                    title: "销毁管理",
                    authCode: 1040000
                },
                children: [{
                        path: "apply",
                        component: () =>
                            import ("../views/destroy-manage/apply-destroy.vue"),
                        meta: {
                            title: "申请销毁",
                            authCode: 1040100
                        },
                    },
                    {
                        path: "temp",
                        name: "DestroyTempList",
                        component: () =>
                            import ("../views/access-manage/access-temp-list.vue"),
                        meta: {
                            title: "临时销毁列表"
                        },
                    },
                    {
                        path: "approve",
                        component: () =>
                            import ("../views/destroy-manage/destroy-approve.vue"),
                        meta: {
                            title: "销毁审批",
                            authCode: 1040200
                        },
                    },
                    {
                        path: "log",
                        name: "destroyLog",
                        component: () =>
                            import ("../views/destroy-manage/destroy-log.vue"),
                        meta: {
                            title: "销毁记录",
                            authCode: 1040300
                        },
                    },
                    {
                        path: "to-apply",
                        meta: {
                            title: "申请",
                            authCode: 1041100,
                            showNav: false
                        },
                    },
                    {
                        path: "no-approve",
                        meta: {
                            title: "不需要审批",
                            authCode: 1041200,
                            showNav: false
                        },
                    },
                ],
            },
            {
                path: "/demand",
                name: "Demand",
                component: () =>
                    import ("../views/demand-manage/index.vue"),
                meta: {
                    title: "需求管理",
                    authCode: 1050000
                },
            },
            {
                path: "/offshelf",
                name: "Offshelf",
                redirect: "/offshelf/log",
                component: () =>
                    import ("../views/offshelf-permanent/index.vue"),
                meta: {
                    title: "永久下架",
                    authCode: 1060000
                },
                children: [{
                        path: "apply",
                        component: () =>
                            import ("../views/offshelf-permanent/apply-offshelf.vue"),
                        meta: {
                            title: "申请永久下架",
                            authCode: 1060100,
                            ignoreRouter: true
                        },
                    },
                    {
                        path: "temp",
                        name: "OffshelfTempList",
                        component: () =>
                            import ("../views/offshelf-permanent/offshelf-temp-list.vue"),
                        meta: {
                            title: "临时下架列表",
                            ignoreRouter: true
                        },
                    },
                    {
                        path: "approve",
                        name: "OffshelfApprove",
                        component: () =>
                            import ("../views/offshelf-permanent/offshelf-approve.vue"),
                        meta: {
                            title: "永久下架审批",
                            authCode: 1060200
                        },
                    },
                    {
                        path: "log",
                        name: "OffshelfLog",
                        component: () =>
                            import ("../views/offshelf-permanent/offshelf-log.vue"),
                        meta: {
                            title: "永久下架记录",
                            authCode: 1060300,
                            ignoreRouter: true
                        },
                    },
                    {
                        path: "boxDetail/:id",
                        name: "OffshelfBoxDetail",
                        component: () =>
                            import ("../views/box-detail.vue"),
                        meta: {
                            title: "窍详情"
                        },
                    },
                ],
            },
        ],
    },
    {
        path: "/login",
        name: "Login",
        component: () =>
            import ("../views/login/login.vue"),
        meta: {
            title: "登录"
        },
    },
    {
        path: "/logout",
        name: "Logout",
        meta: {
            title: "退出登录"
        },
    },
    {
        path: "/forgot-password",
        name: "ForgotPassword",
        component: () =>
            import ('../views/forgot-password/index.vue'),
        meta: {
            title: "忘记密码"
        },
    },
    {
        path: "/oaLogin",
        name: "OALogin",
        component: () =>
            import ('../views/oa-login/index.vue'),
        meta: {
            title: "客服登录"
        },
    },
    {
        path: "/mobileLogin",
        name: "MobileLogin",
        component: () =>
            import ("../views/mobile/mobile-login.vue"),
        meta: {
            title: "手机登录"
        },
    },
    {
        path: "*",
        name: "404",
        meta: {
            title: "404"
        },
        component: () =>
            import ("../views/error/404.vue"),
    },
    {
        path: "/mobile",
        name: "mobile",
        redirect: "/mobile/retrieval/approve",
        component: () =>
            import ('../views/mobile/index.vue'),
        meta: {
            title: "移动端"
        },
        children: [{
                path: "retrieval/approve",
                name: "BorrowApproval",
                component: () =>
                    import ('../views/mobile/approval.vue'),
                meta: {
                    title: "调阅审批"
                },
            },
            {
                path: "destroy/approve",
                name: "DestroyApproval",
                component: () =>
                    import ('../views/mobile/approval.vue'),
                meta: {
                    title: "销毁审批"
                },
            },
            {
                path: "offshelf/approve",
                name: "OffShelfApproval",
                component: () =>
                    import ('../views/mobile/approval.vue'),
                meta: {
                    title: "永久下架审批"
                },
            },
            {
                path: "entrance",
                name: "EntranceInfo",
                component: () =>
                    import ('../views/mobile/entrance.vue'),
                meta: {
                    title: "来访人员基本信息"
                },
            },
            {
                path: "entry-application",
                name: "entryApplication",
                component: () =>
                    import ('../views/mobile/entry-apply-demo.vue'),
                meta: {
                    title: "入门申请审批"
                },
            },
            {
                path: "take/:orderNum",
                name: "TakeBoxList",
                component: () =>
                    import ('../views/mobile/take.vue'),
                meta: {
                    title: "档案提走_审批"
                },
            },
            {
                path: "apply/empty",
                name: "applyEmptyConfirm",
                component: () =>
                    import ('../views/mobile/apply-empty-confirm.vue'),
                meta: {
                    title: "申请空窍"
                    // 申请空窍, ... 客户确认签收
                },
            },
        ],
    },
];

const router = new VueRouter({
    mode: "history",
    // mode: "hash",
    base: process.env.BASE_URL,
    routes,
});

const VueRouterPush = VueRouter.prototype.push;
// 去除重复路由操作
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch((err) => err);
};

// 路由 守卫
router.beforeEach((to, from, next) => {
    // 更改每页的提交
    document.title = to.meta.title + "-窍楚档案";
    document.documentElement.scrollTop = 0;
    next();
});

export default router;